/**
 * @(#)TuanGouWebItem.java, 2010-5-16. 
 * 
 */
package com.rsstuan.data;

import java.io.Serializable;

import com.rsstuan.storage.data.TuanGouItemData;

/**
 *
 * @author guosq
 *
 */
public class TuanGouWebItem extends TuanGouItemData implements Serializable{

    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private String siteName;
	
	private String feedDescription;
	
	private String rssPubTime;

    /**
     * @param item
     */
    public TuanGouWebItem(TuanGouItemData item) {
       this.setTitle(item.getTitle());
       this.setImage(item.getImage());
       this.setPrice(item.getPrice());
       this.setOrigPrice(item.getOrigPrice());
       this.setOrderNum(item.getOrderNum());
       this.setDescription(item.getDescription());
       this.setStartTime(item.getStartTime());
       this.setEndTime(item.getEndTime());
       this.setChannelId(item.getChannelId());
       this.setCity(item.getCity());
       this.setId(item.getId());
       this.setLink(item.getLink());
       this.setAddress(item.getAddress());
       this.setPubTime(item.getPubTime());
    }
    
    public TuanGouWebItem(String json) {
    	readJasonString(json);
		
	}

	/**
     * 
     */
    public TuanGouWebItem() {
        super();    
    }

    public String toJasonString() {
    	StringBuilder sb = new StringBuilder();
    	sb.append("id=" + this.getId());
    	sb.append(" titleLen=" + this.getTitle().length());
    	sb.append(" title=" + this.getTitle());
    	sb.append(" image=" + this.getImage());
    	sb.append(" price=" + this.getPrice());
    	sb.append(" origPrice=" + this.getOrigPrice());
    	sb.append(" orderNum=" + this.getOrderNum());
    	//sb.append(" description=" + this.getDescription());
    	sb.append(" startTime=" + this.getStartTime());
    	sb.append(" endTime=" + this.getEndTime());
    	sb.append(" channelId=" + this.getChannelId());
    	sb.append(" city="+this.getCity());
    	sb.append(" link=" + this.getLink());
    	sb.append(" address=" + this.getAddress());
    	sb.append(" pubTime=" + this.getPubTime());
    	
    	return sb.toString();
    }
    
    public void readJasonString(String str) {
    	int equal = str.indexOf("=");
    	int space = str.indexOf(" ");
    	this.setId(Long.parseLong(str.substring(equal+1, space)));
    	
    	equal = str.indexOf("=", space + 1 );
    	space = str.indexOf(" ", equal);
    	int titleLen = Integer.parseInt(str.substring(equal+1, space));
    	
    	equal = str.indexOf("=", space + 1 );
    	space = str.indexOf(" ", equal + titleLen);
    	this.setTitle(str.substring(equal+1, space));
    	
    	equal = str.indexOf("=", space + 1 );
    	space = str.indexOf(" ", equal);
    	this.setImage(str.substring(equal+1, space));
    	
    	equal = str.indexOf("=", space + 1 );
    	space = str.indexOf(" ", equal);
    	this.setPrice(Double.parseDouble(str.substring(equal+1, space)));
    	
    	equal = str.indexOf("=", space + 1 );
    	space = str.indexOf(" ", equal);
    	this.setOrigPrice(Double.parseDouble(str.substring(equal+1, space)));
    	
    	equal = str.indexOf("=", space + 1 );
    	space = str.indexOf(" ", equal);
    	this.setOrderNum(Integer.parseInt(str.substring(equal+1, space)));
    
    	
    	/*equal = str.indexOf("=", space + 1 );
    	space = str.indexOf(" ", equal);
    	this.setDescription(str.substring(equal+1, space));*/
    	
    	equal = str.indexOf("=", space + 1 );
    	space = str.indexOf(" ", equal);
    	this.setStartTime(Long.parseLong(str.substring(equal+1, space)));
    	
    	equal = str.indexOf("=", space + 1 );
    	space = str.indexOf(" ", equal);
    	this.setEndTime(Long.parseLong(str.substring(equal+1, space)));
    	
    	equal = str.indexOf("=", space + 1 );
    	space = str.indexOf(" ", equal);
    	this.setChannelId(Long.parseLong(str.substring(equal+1, space)));
    	
    	equal = str.indexOf("=", space + 1 );
    	space = str.indexOf(" ", equal);
    	this.setCity(str.substring(equal+1, space));
    	
    	equal = str.indexOf("=", space + 1 );
    	space = str.indexOf(" ", equal);
    	this.setLink(str.substring(equal+1, space));
    	
    	equal = str.indexOf("=", space + 1 );
    	space = str.indexOf(" ", equal);
    	this.setAddress(str.substring(equal+1, space));
    	
    	equal = str.indexOf("=", space + 1 );
    	this.setPubTime(Long.parseLong(str.substring(equal+1)));
    	
    	
    }

    public void setSiteName(String siteName) {
        this.siteName = siteName;
    }

    public String getSiteName() {
        return siteName;
    }

    public void setFeedDescription(String feedDescription) {
        this.feedDescription = feedDescription;
    }

    public String getFeedDescription() {
        return feedDescription;
    }

    public void setRssPubTime(String rssPubTime) {
        this.rssPubTime = rssPubTime;
    }

    public String getRssPubTime() {
        return rssPubTime;
    }
    
    
}
